<?php
namespace model;

use think\Model;

class Permission extends Model{

    public function roles(){
        return $this->belongsToMany('RolePermission', 'pid');
    }

    public static function bulid_tree(){
        $tmp = self::all();
        foreach($tmp as $k => $v){
            $tmp[$k] = $v->visible([
                'id',
                'pid',
                'key',
                'name',
                'icon'
            ])->toArray();
        }
        return tree_parse($tmp);
    }
}